home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / webkit / resources.pak / Unnamed File 000124.txt < prev    next >
Text File  |  2013-04-03  |  30KB  |  965 lines

  1. (function() {
  2.     /*
  3.  * Copyright (C) 2012 Google Inc. All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions are
  7.  * met:
  8.  *
  9.  *     * Redistributions of source code must retain the above copyright
  10.  * notice, this list of conditions and the following disclaimer.
  11.  *     * Redistributions in binary form must reproduce the above
  12.  * copyright notice, this list of conditions and the following disclaimer
  13.  * in the documentation and/or other materials provided with the
  14.  * distribution.
  15.  *     * Neither the name of Google Inc. nor the names of its
  16.  * contributors may be used to endorse or promote products derived from
  17.  * this software without specific prior written permission.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30.  */
  31.  
  32. function defineCommonExtensionSymbols(apiPrivate)
  33. {
  34.     if (!apiPrivate.audits)
  35.         apiPrivate.audits = {};
  36.     apiPrivate.audits.Severity = {
  37.         Info: "info",
  38.         Warning: "warning",
  39.         Severe: "severe"
  40.     };
  41.  
  42.     if (!apiPrivate.console)
  43.         apiPrivate.console = {};
  44.     apiPrivate.console.Severity = {
  45.         Tip: "tip",
  46.         Debug: "debug",
  47.         Log: "log",
  48.         Warning: "warning",
  49.         Error: "error"
  50.     };
  51.  
  52.     if (!apiPrivate.panels)
  53.         apiPrivate.panels = {};
  54.     apiPrivate.panels.SearchAction = {
  55.         CancelSearch: "cancelSearch",
  56.         PerformSearch: "performSearch",
  57.         NextSearchResult: "nextSearchResult",
  58.         PreviousSearchResult: "previousSearchResult"
  59.     };
  60.  
  61.     apiPrivate.Events = {
  62.         AuditStarted: "audit-started-",
  63.         ButtonClicked: "button-clicked-",
  64.         ConsoleMessageAdded: "console-message-added",
  65.         ElementsPanelObjectSelected: "panel-objectSelected-elements",
  66.         NetworkRequestFinished: "network-request-finished",
  67.         Reset: "reset",
  68.         OpenResource: "open-resource",
  69.         PanelSearch: "panel-search-",
  70.         Reload: "Reload",
  71.         ResourceAdded: "resource-added",
  72.         ResourceContentCommitted: "resource-content-committed",
  73.         TimelineEventRecorded: "timeline-event-recorded",
  74.         ViewShown: "view-shown-",
  75.         ViewHidden: "view-hidden-"
  76.     };
  77.  
  78.     apiPrivate.Commands = {
  79.         AddAuditCategory: "addAuditCategory",
  80.         AddAuditResult: "addAuditResult",
  81.         AddConsoleMessage: "addConsoleMessage",
  82.         AddRequestHeaders: "addRequestHeaders",
  83.         CreatePanel: "createPanel",
  84.         CreateSidebarPane: "createSidebarPane",
  85.         CreateStatusBarButton: "createStatusBarButton",
  86.         EvaluateOnInspectedPage: "evaluateOnInspectedPage",
  87.         GetConsoleMessages: "getConsoleMessages",
  88.         GetHAR: "getHAR",
  89.         GetPageResources: "getPageResources",
  90.         GetRequestContent: "getRequestContent",
  91.         GetResourceContent: "getResourceContent",
  92.         Subscribe: "subscribe",
  93.         SetOpenResourceHandler: "setOpenResourceHandler",
  94.         SetResourceContent: "setResourceContent",
  95.         SetSidebarContent: "setSidebarContent",
  96.         SetSidebarHeight: "setSidebarHeight",
  97.         SetSidebarPage: "setSidebarPage",
  98.         ShowPanel: "showPanel",
  99.         StopAuditCategoryRun: "stopAuditCategoryRun",
  100.         Unsubscribe: "unsubscribe",
  101.         UpdateAuditProgress: "updateAuditProgress",
  102.         UpdateButton: "updateButton",
  103.         InspectedURLChanged: "inspectedURLChanged"
  104.     };
  105. }
  106.  
  107. function injectedExtensionAPI(injectedScriptId)
  108. {
  109.  
  110. var apiPrivate = {};
  111.  
  112. defineCommonExtensionSymbols(apiPrivate);
  113.  
  114. var commands = apiPrivate.Commands;
  115. var events = apiPrivate.Events;
  116. var userAction = false;
  117.  
  118. // Here and below, all constructors are private to API implementation.
  119. // For a public type Foo, if internal fields are present, these are on
  120. // a private FooImpl type, an instance of FooImpl is used in a closure
  121. // by Foo consutrctor to re-bind publicly exported members to an instance
  122. // of Foo.
  123.  
  124. /**
  125.  * @constructor
  126.  */
  127. function EventSinkImpl(type, customDispatch)
  128. {
  129.     this._type = type;
  130.     this._listeners = [];
  131.     this._customDispatch = customDispatch;
  132. }
  133.  
  134. EventSinkImpl.prototype = {
  135.     addListener: function(callback)
  136.     {
  137.         if (typeof callback !== "function")
  138.             throw "addListener: callback is not a function";
  139.         if (this._listeners.length === 0)
  140.             extensionServer.sendRequest({ command: commands.Subscribe, type: this._type });
  141.         this._listeners.push(callback);
  142.         extensionServer.registerHandler("notify-" + this._type, this._dispatch.bind(this));
  143.     },
  144.  
  145.     removeListener: function(callback)
  146.     {
  147.         var listeners = this._listeners;
  148.  
  149.         for (var i = 0; i < listeners.length; ++i) {
  150.             if (listeners[i] === callback) {
  151.                 listeners.splice(i, 1);
  152.                 break;
  153.             }
  154.         }
  155.         if (this._listeners.length === 0)
  156.             extensionServer.sendRequest({ command: commands.Unsubscribe, type: this._type });
  157.     },
  158.  
  159.     _fire: function()
  160.     {
  161.         var listeners = this._listeners.slice();
  162.         for (var i = 0; i < listeners.length; ++i)
  163.             listeners[i].apply(null, arguments);
  164.     },
  165.  
  166.     _dispatch: function(request)
  167.     {
  168.          if (this._customDispatch)
  169.              this._customDispatch.call(this, request);
  170.          else
  171.              this._fire.apply(this, request.arguments);
  172.     }
  173. }
  174.  
  175. /**
  176.  * @constructor
  177.  */
  178. function InspectorExtensionAPI()
  179. {
  180.     this.audits = new Audits();
  181.     this.inspectedWindow = new InspectedWindow();
  182.     this.panels = new Panels();
  183.     this.network = new Network();
  184.     defineDeprecatedProperty(this, "webInspector", "resources", "network");
  185.     this.timeline = new Timeline();
  186.     this.console = new ConsoleAPI();
  187.  
  188.     this.onReset = new EventSink(events.Reset);
  189. }
  190.  
  191. /**
  192.  * @constructor
  193.  */
  194. InspectorExtensionAPI.prototype = {
  195.     log: function(message)
  196.     {
  197.         extensionServer.sendRequest({ command: commands.Log, message: message });
  198.     }
  199. }
  200.  
  201. /**
  202.  * @constructor
  203.  */
  204. function ConsoleAPI()
  205. {
  206.     this.onMessageAdded = new EventSink(events.ConsoleMessageAdded);
  207. }
  208.  
  209. ConsoleAPI.prototype = {
  210.     getMessages: function(callback)
  211.     {
  212.         extensionServer.sendRequest({ command: commands.GetConsoleMessages }, callback);
  213.     },
  214.  
  215.     addMessage: function(severity, text, url, line)
  216.     {
  217.         extensionServer.sendRequest({ command: commands.AddConsoleMessage, severity: severity, text: text, url: url, line: line });
  218.     },
  219.  
  220.     get Severity()
  221.     {
  222.         return apiPrivate.console.Severity;
  223.     }
  224. }
  225.  
  226. /**
  227.  * @constructor
  228.  */
  229. function Network()
  230. {
  231.     function dispatchRequestEvent(message)
  232.     {
  233.         var request = message.arguments[1];
  234.         request.__proto__ = new Request(message.arguments[0]);
  235.         this._fire(request);
  236.     }
  237.     this.onRequestFinished = new EventSink(events.NetworkRequestFinished, dispatchRequestEvent);
  238.     defineDeprecatedProperty(this, "network", "onFinished", "onRequestFinished");
  239.     this.onNavigated = new EventSink(events.InspectedURLChanged);
  240. }
  241.  
  242. Network.prototype = {
  243.     getHAR: function(callback)
  244.     {
  245.         function callbackWrapper(result)
  246.         {
  247.             var entries = (result && result.entries) || [];
  248.             for (var i = 0; i < entries.length; ++i) {
  249.                 entries[i].__proto__ = new Request(entries[i]._requestId);
  250.                 delete entries[i]._requestId;
  251.             }
  252.             callback(result);
  253.         }
  254.         return extensionServer.sendRequest({ command: commands.GetHAR }, callback && callbackWrapper);
  255.     },
  256.  
  257.     addRequestHeaders: function(headers)
  258.     {
  259.         return extensionServer.sendRequest({ command: commands.AddRequestHeaders, headers: headers, extensionId: window.location.hostname });
  260.     }
  261. }
  262.  
  263. /**
  264.  * @constructor
  265.  */
  266. function RequestImpl(id)
  267. {
  268.     this._id = id;
  269. }
  270.  
  271. RequestImpl.prototype = {
  272.     getContent: function(callback)
  273.     {
  274.         function callbackWrapper(response)
  275.         {
  276.             callback(response.content, response.encoding);
  277.         }
  278.         extensionServer.sendRequest({ command: commands.GetRequestContent, id: this._id }, callback && callbackWrapper);
  279.     }
  280. }
  281.  
  282. /**
  283.  * @constructor
  284.  */
  285. function Panels()
  286. {
  287.     var panels = {
  288.         elements: new ElementsPanel()
  289.     };
  290.  
  291.     function panelGetter(name)
  292.     {
  293.         return panels[name];
  294.     }
  295.     for (var panel in panels)
  296.         this.__defineGetter__(panel, panelGetter.bind(null, panel));
  297. }
  298.  
  299. Panels.prototype = {
  300.     create: function(title, icon, page, callback)
  301.     {
  302.         var id = "extension-panel-" + extensionServer.nextObjectId();
  303.         var request = {
  304.             command: commands.CreatePanel,
  305.             id: id,
  306.             title: title,
  307.             icon: icon,
  308.             page: page
  309.         };
  310.         extensionServer.sendRequest(request, callback && callback.bind(this, new ExtensionPanel(id)));
  311.     },
  312.  
  313.     setOpenResourceHandler: function(callback)
  314.     {
  315.         var hadHandler = extensionServer.hasHandler(events.OpenResource);
  316.  
  317.         if (!callback)
  318.             extensionServer.unregisterHandler(events.OpenResource);
  319.         else {
  320.             function callbackWrapper(message)
  321.             {
  322.                 // Allow the panel to show itself when handling the event.
  323.                 userAction = true;
  324.                 try {
  325.                     callback.call(null, new Resource(message.resource), message.lineNumber);
  326.                 } finally {
  327.                     userAction = false;
  328.                 }
  329.             }
  330.             extensionServer.registerHandler(events.OpenResource, callbackWrapper);
  331.         }
  332.         // Only send command if we either removed an existing handler or added handler and had none before.
  333.         if (hadHandler === !callback)
  334.             extensionServer.sendRequest({ command: commands.SetOpenResourceHandler, "handlerPresent": !!callback });
  335.     },
  336.  
  337.     get SearchAction()
  338.     {
  339.         return apiPrivate.panels.SearchAction;
  340.     }
  341. }
  342.  
  343. /**
  344.  * @constructor
  345.  */
  346. function ExtensionViewImpl(id)
  347. {
  348.     this._id = id;
  349.  
  350.     function dispatchShowEvent(message)
  351.     {
  352.         var frameIndex = message.arguments[0];
  353.         this._fire(window.parent.frames[frameIndex]);
  354.     }
  355.     this.onShown = new EventSink(events.ViewShown + id, dispatchShowEvent);
  356.     this.onHidden = new EventSink(events.ViewHidden + id);
  357. }
  358.  
  359. /**
  360.  * @constructor
  361.  */
  362. function PanelWithSidebarImpl(id)
  363. {
  364.     this._id = id;
  365. }
  366.  
  367. PanelWithSidebarImpl.prototype = {
  368.     createSidebarPane: function(title, callback)
  369.     {
  370.         var id = "extension-sidebar-" + extensionServer.nextObjectId();
  371.         var request = {
  372.             command: commands.CreateSidebarPane,
  373.             panel: this._id,
  374.             id: id,
  375.             title: title
  376.         };
  377.         function callbackWrapper()
  378.         {
  379.             callback(new ExtensionSidebarPane(id));
  380.         }
  381.         extensionServer.sendRequest(request, callback && callbackWrapper);
  382.     },
  383.  
  384.     __proto__: ExtensionViewImpl.prototype
  385. }
  386.  
  387. /**
  388.  * @constructor
  389.  * @extends {PanelWithSidebar}
  390.  */
  391. function ElementsPanel()
  392. {
  393.     var id = "elements";
  394.     PanelWithSidebar.call(this, id);
  395.     this.onSelectionChanged = new EventSink(events.ElementsPanelObjectSelected);
  396. }
  397.  
  398. /**
  399.  * @constructor
  400.  * @extends {ExtensionViewImpl}
  401.  */
  402. function ExtensionPanelImpl(id)
  403. {
  404.     ExtensionViewImpl.call(this, id);
  405.     this.onSearch = new EventSink(events.PanelSearch + id);
  406. }
  407.  
  408. ExtensionPanelImpl.prototype = {
  409.     createStatusBarButton: function(iconPath, tooltipText, disabled)
  410.     {
  411.         var id = "button-" + extensionServer.nextObjectId();
  412.         var request = {
  413.             command: commands.CreateStatusBarButton,
  414.             panel: this._id,
  415.             id: id,
  416.             icon: iconPath,
  417.             tooltip: tooltipText,
  418.             disabled: !!disabled
  419.         };
  420.         extensionServer.sendRequest(request);
  421.         return new Button(id);
  422.     },
  423.  
  424.     show: function()
  425.     {
  426.         if (!userAction)
  427.             return;
  428.  
  429.         var request = {
  430.             command: commands.ShowPanel,
  431.             id: this._id
  432.         };
  433.         extensionServer.sendRequest(request);
  434.     },
  435.  
  436.     __proto__: ExtensionViewImpl.prototype
  437. }
  438.  
  439. /**
  440.  * @constructor
  441.  * @extends {ExtensionViewImpl}
  442.  */
  443. function ExtensionSidebarPaneImpl(id)
  444. {
  445.     ExtensionViewImpl.call(this, id);
  446. }
  447.  
  448. ExtensionSidebarPaneImpl.prototype = {
  449.     setHeight: function(height)
  450.     {
  451.         extensionServer.sendRequest({ command: commands.SetSidebarHeight, id: this._id, height: height });
  452.     },
  453.  
  454.     setExpression: function(expression, rootTitle, evaluateOptions)
  455.     {
  456.         var callback = extractCallbackArgument(arguments);
  457.         var request = {
  458.             command: commands.SetSidebarContent,
  459.             id: this._id,
  460.             expression: expression,
  461.             rootTitle: rootTitle,
  462.             evaluateOnPage: true,
  463.         };
  464.         if (typeof evaluateOptions === "object")
  465.             request.evaluateOptions = evaluateOptions;
  466.         extensionServer.sendRequest(request, callback);
  467.     },
  468.  
  469.     setObject: function(jsonObject, rootTitle, callback)
  470.     {
  471.         extensionServer.sendRequest({ command: commands.SetSidebarContent, id: this._id, expression: jsonObject, rootTitle: rootTitle }, callback);
  472.     },
  473.  
  474.     setPage: function(page)
  475.     {
  476.         extensionServer.sendRequest({ command: commands.SetSidebarPage, id: this._id, page: page });
  477.     }
  478. }
  479.  
  480. /**
  481.  * @constructor
  482.  */
  483. function ButtonImpl(id)
  484. {
  485.     this._id = id;
  486.     this.onClicked = new EventSink(events.ButtonClicked + id);
  487. }
  488.  
  489. ButtonImpl.prototype = {
  490.     update: function(iconPath, tooltipText, disabled)
  491.     {
  492.         var request = {
  493.             command: commands.UpdateButton,
  494.             id: this._id,
  495.             icon: iconPath,
  496.             tooltip: tooltipText,
  497.             disabled: !!disabled
  498.         };
  499.         extensionServer.sendRequest(request);
  500.     }
  501. };
  502.  
  503. /**
  504.  * @constructor
  505.  */
  506. function Audits()
  507. {
  508. }
  509.  
  510. Audits.prototype = {
  511.     addCategory: function(displayName, resultCount)
  512.     {
  513.         var id = "extension-audit-category-" + extensionServer.nextObjectId();
  514.         if (typeof resultCount !== "undefined")
  515.             console.warn("Passing resultCount to audits.addCategory() is deprecated. Use AuditResult.updateProgress() instead.");
  516.         extensionServer.sendRequest({ command: commands.AddAuditCategory, id: id, displayName: displayName, resultCount: resultCount });
  517.         return new AuditCategory(id);
  518.     }
  519. }
  520.  
  521. /**
  522.  * @constructor
  523.  */
  524. function AuditCategoryImpl(id)
  525. {
  526.     function dispatchAuditEvent(request)
  527.     {
  528.         var auditResult = new AuditResult(request.arguments[0]);
  529.         try {
  530.             this._fire(auditResult);
  531.         } catch (e) {
  532.             console.error("Uncaught exception in extension audit event handler: " + e);
  533.             auditResult.done();
  534.         }
  535.     }
  536.     this._id = id;
  537.     this.onAuditStarted = new EventSink(events.AuditStarted + id, dispatchAuditEvent);
  538. }
  539.  
  540. /**
  541.  * @constructor
  542.  */
  543. function AuditResultImpl(id)
  544. {
  545.     this._id = id;
  546.  
  547.     this.createURL = this._nodeFactory.bind(null, "url");
  548.     this.createSnippet = this._nodeFactory.bind(null, "snippet");
  549.     this.createText = this._nodeFactory.bind(null, "text");
  550.     this.createObject = this._nodeFactory.bind(null, "object");
  551.     this.createNode = this._nodeFactory.bind(null, "node");
  552. }
  553.  
  554. AuditResultImpl.prototype = {
  555.     addResult: function(displayName, description, severity, details)
  556.     {
  557.         // shorthand for specifying details directly in addResult().
  558.         if (details && !(details instanceof AuditResultNode))
  559.             details = new AuditResultNode(details instanceof Array ? details : [details]);
  560.  
  561.         var request = {
  562.             command: commands.AddAuditResult,
  563.             resultId: this._id,
  564.             displayName: displayName,
  565.             description: description,
  566.             severity: severity,
  567.             details: details
  568.         };
  569.         extensionServer.sendRequest(request);
  570.     },
  571.  
  572.     createResult: function()
  573.     {
  574.         return new AuditResultNode(Array.prototype.slice.call(arguments));
  575.     },
  576.  
  577.     updateProgress: function(worked, totalWork)
  578.     {
  579.         extensionServer.sendRequest({ command: commands.UpdateAuditProgress, resultId: this._id, progress: worked / totalWork });
  580.     },
  581.  
  582.     done: function()
  583.     {
  584.         extensionServer.sendRequest({ command: commands.StopAuditCategoryRun, resultId: this._id });
  585.     },
  586.  
  587.     get Severity()
  588.     {
  589.         return apiPrivate.audits.Severity;
  590.     },
  591.  
  592.     createResourceLink: function(url, lineNumber)
  593.     {
  594.         return {
  595.             type: "resourceLink",
  596.             arguments: [url, lineNumber && lineNumber - 1]
  597.         };
  598.     },
  599.  
  600.     _nodeFactory: function(type)
  601.     {
  602.         return {
  603.             type: type,
  604.             arguments: Array.prototype.slice.call(arguments, 1)
  605.         };
  606.     }
  607. }
  608.  
  609. /**
  610.  * @constructor
  611.  */
  612. function AuditResultNode(contents)
  613. {
  614.     this.contents = contents;
  615.     this.children = [];
  616.     this.expanded = false;
  617. }
  618.  
  619. AuditResultNode.prototype = {
  620.     addChild: function()
  621.     {
  622.         var node = new AuditResultNode(Array.prototype.slice.call(arguments));
  623.         this.children.push(node);
  624.         return node;
  625.     }
  626. };
  627.  
  628. /**
  629.  * @constructor
  630.  */
  631. function InspectedWindow()
  632. {
  633.     function dispatchResourceEvent(message)
  634.     {
  635.         this._fire(new Resource(message.arguments[0]));
  636.     }
  637.     function dispatchResourceContentEvent(message)
  638.     {
  639.         this._fire(new Resource(message.arguments[0]), message.arguments[1]);
  640.     }
  641.     this.onResourceAdded = new EventSink(events.ResourceAdded, dispatchResourceEvent);
  642.     this.onResourceContentCommitted = new EventSink(events.ResourceContentCommitted, dispatchResourceContentEvent);
  643. }
  644.  
  645. InspectedWindow.prototype = {
  646.     reload: function(optionsOrUserAgent)
  647.     {
  648.         var options = null;
  649.         if (typeof optionsOrUserAgent === "object")
  650.             options = optionsOrUserAgent;
  651.         else if (typeof optionsOrUserAgent === "string") {
  652.             options = { userAgent: optionsOrUserAgent };
  653.             console.warn("Passing userAgent as string parameter to inspectedWindow.reload() is deprecated. " +
  654.                          "Use inspectedWindow.reload({ userAgent: value}) instead.");
  655.         }
  656.         return extensionServer.sendRequest({ command: commands.Reload, options: options });
  657.     },
  658.  
  659.     eval: function(expression, evaluateOptions)
  660.     {
  661.         var callback = extractCallbackArgument(arguments);
  662.         function callbackWrapper(result)
  663.         {
  664.             callback(result.value, result.isException);
  665.         }
  666.         var request = {
  667.             command: commands.EvaluateOnInspectedPage,
  668.             expression: expression
  669.         };
  670.         if (typeof evaluateOptions === "object")
  671.             request.evaluateOptions = evaluateOptions;
  672.         return extensionServer.sendRequest(request, callback && callbackWrapper);
  673.     },
  674.  
  675.     getResources: function(callback)
  676.     {
  677.         function wrapResource(resourceData)
  678.         {
  679.             return new Resource(resourceData);
  680.         }
  681.         function callbackWrapper(resources)
  682.         {
  683.             callback(resources.map(wrapResource));
  684.         }
  685.         return extensionServer.sendRequest({ command: commands.GetPageResources }, callback && callbackWrapper);
  686.     }
  687. }
  688.  
  689. /**
  690.  * @constructor
  691.  */
  692. function ResourceImpl(resourceData)
  693. {
  694.     this._url = resourceData.url
  695.     this._type = resourceData.type;
  696. }
  697.  
  698. ResourceImpl.prototype = {
  699.     get url()
  700.     {
  701.         return this._url;
  702.     },
  703.  
  704.     get type()
  705.     {
  706.         return this._type;
  707.     },
  708.  
  709.     getContent: function(callback)
  710.     {
  711.         function callbackWrapper(response)
  712.         {
  713.             callback(response.content, response.encoding);
  714.         }
  715.  
  716.         return extensionServer.sendRequest({ command: commands.GetResourceContent, url: this._url }, callback && callbackWrapper);
  717.     },
  718.  
  719.     setContent: function(content, commit, callback)
  720.     {
  721.         return extensionServer.sendRequest({ command: commands.SetResourceContent, url: this._url, content: content, commit: commit }, callback);
  722.     }
  723. }
  724.  
  725. /**
  726.  * @constructor
  727.  */
  728. function TimelineImpl()
  729. {
  730.     this.onEventRecorded = new EventSink(events.TimelineEventRecorded);
  731. }
  732.  
  733. /**
  734.  * @constructor
  735.  */
  736. function ExtensionServerClient()
  737. {
  738.     this._callbacks = {};
  739.     this._handlers = {};
  740.     this._lastRequestId = 0;
  741.     this._lastObjectId = 0;
  742.  
  743.     this.registerHandler("callback", this._onCallback.bind(this));
  744.  
  745.     var channel = new MessageChannel();
  746.     this._port = channel.port1;
  747.     this._port.addEventListener("message", this._onMessage.bind(this), false);
  748.     this._port.start();
  749.  
  750.     window.parent.postMessage("registerExtension", [ channel.port2 ], "*");
  751. }
  752.  
  753. ExtensionServerClient.prototype = {
  754.     /**
  755.      * @param {function()=} callback
  756.      */
  757.     sendRequest: function(message, callback)
  758.     {
  759.         if (typeof callback === "function")
  760.             message.requestId = this._registerCallback(callback);
  761.         return this._port.postMessage(message);
  762.     },
  763.  
  764.     hasHandler: function(command)
  765.     {
  766.         return !!this._handlers[command];
  767.     },
  768.  
  769.     registerHandler: function(command, handler)
  770.     {
  771.         this._handlers[command] = handler;
  772.     },
  773.  
  774.     unregisterHandler: function(command)
  775.     {
  776.         delete this._handlers[command];
  777.     },
  778.  
  779.     nextObjectId: function()
  780.     {
  781.         return injectedScriptId + "_" + ++this._lastObjectId;
  782.     },
  783.  
  784.     _registerCallback: function(callback)
  785.     {
  786.         var id = ++this._lastRequestId;
  787.         this._callbacks[id] = callback;
  788.         return id;
  789.     },
  790.  
  791.     _onCallback: function(request)
  792.     {
  793.         if (request.requestId in this._callbacks) {
  794.             var callback = this._callbacks[request.requestId];
  795.             delete this._callbacks[request.requestId];
  796.             callback(request.result);
  797.         }
  798.     },
  799.  
  800.     _onMessage: function(event)
  801.     {
  802.         var request = event.data;
  803.         var handler = this._handlers[request.command];
  804.         if (handler)
  805.             handler.call(this, request);
  806.     }
  807. }
  808.  
  809. function populateInterfaceClass(interface, implementation)
  810. {
  811.     for (var member in implementation) {
  812.         if (member.charAt(0) === "_")
  813.             continue;
  814.         var descriptor = null;
  815.         // Traverse prototype chain until we find the owner.
  816.         for (var owner = implementation; owner && !descriptor; owner = owner.__proto__)
  817.             descriptor = Object.getOwnPropertyDescriptor(owner, member);
  818.         if (!descriptor)
  819.             continue;
  820.         if (typeof descriptor.value === "function")
  821.             interface[member] = descriptor.value.bind(implementation);
  822.         else if (typeof descriptor.get === "function")
  823.             interface.__defineGetter__(member, descriptor.get.bind(implementation));
  824.         else
  825.             Object.defineProperty(interface, member, descriptor);
  826.     }
  827. }
  828.  
  829. function declareInterfaceClass(implConstructor)
  830. {
  831.     return function()
  832.     {
  833.         var impl = { __proto__: implConstructor.prototype };
  834.         implConstructor.apply(impl, arguments);
  835.         populateInterfaceClass(this, impl);
  836.     }
  837. }
  838.  
  839. function defineDeprecatedProperty(object, className, oldName, newName)
  840. {
  841.     var warningGiven = false;
  842.     function getter()
  843.     {
  844.         if (!warningGiven) {
  845.             console.warn(className + "." + oldName + " is deprecated. Use " + className + "." + newName + " instead");
  846.             warningGiven = true;
  847.         }
  848.         return object[newName];
  849.     }
  850.     object.__defineGetter__(oldName, getter);
  851. }
  852.  
  853. function extractCallbackArgument(args)
  854. {
  855.     var lastArgument = args[args.length - 1];
  856.     return typeof lastArgument === "function" ? lastArgument : undefined;
  857. }
  858.  
  859. var AuditCategory = declareInterfaceClass(AuditCategoryImpl);
  860. var AuditResult = declareInterfaceClass(AuditResultImpl);
  861. var Button = declareInterfaceClass(ButtonImpl);
  862. var EventSink = declareInterfaceClass(EventSinkImpl);
  863. var ExtensionPanel = declareInterfaceClass(ExtensionPanelImpl);
  864. var ExtensionSidebarPane = declareInterfaceClass(ExtensionSidebarPaneImpl);
  865. var PanelWithSidebar = declareInterfaceClass(PanelWithSidebarImpl);
  866. var Request = declareInterfaceClass(RequestImpl);
  867. var Resource = declareInterfaceClass(ResourceImpl);
  868. var Timeline = declareInterfaceClass(TimelineImpl);
  869.  
  870. var extensionServer = new ExtensionServerClient();
  871.  
  872. return new InspectorExtensionAPI();
  873. }
  874.  
  875. // Default implementation; platforms will override.
  876. function buildPlatformExtensionAPI(extensionInfo)
  877. {
  878.     function platformExtensionAPI(coreAPI)
  879.     {
  880.         window.webInspector = coreAPI;
  881.     }
  882.     return platformExtensionAPI.toString();
  883. }
  884.  
  885.  
  886. function buildExtensionAPIInjectedScript(extensionInfo)
  887. {
  888.     return "(function(injectedScriptHost, inspectedWindow, injectedScriptId){ " +
  889.         defineCommonExtensionSymbols.toString() + ";" +
  890.         injectedExtensionAPI.toString() + ";" +
  891.         buildPlatformExtensionAPI(extensionInfo) + ";" +
  892.         "platformExtensionAPI(injectedExtensionAPI(injectedScriptId));" +
  893.         "return {};" +
  894.         "})";
  895. }
  896. /*
  897.  * Copyright (C) 2011 Google Inc. All rights reserved.
  898.  *
  899.  * Redistribution and use in source and binary forms, with or without
  900.  * modification, are permitted provided that the following conditions are
  901.  * met:
  902.  *
  903.  *     * Redistributions of source code must retain the above copyright
  904.  * notice, this list of conditions and the following disclaimer.
  905.  *     * Redistributions in binary form must reproduce the above
  906.  * copyright notice, this list of conditions and the following disclaimer
  907.  * in the documentation and/or other materials provided with the
  908.  * distribution.
  909.  *     * Neither the name of Google Inc. nor the names of its
  910.  * contributors may be used to endorse or promote products derived from
  911.  * this software without specific prior written permission.
  912.  *
  913.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  914.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  915.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  916.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  917.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  918.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  919.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  920.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  921.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  922.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  923.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  924.  */
  925.  
  926. function platformExtensionAPI(coreAPI)
  927. {
  928.     function getTabId()
  929.     {
  930.         return tabId;
  931.     }
  932.     chrome = window.chrome || {};
  933.     // Override chrome.devtools as a workaround for a error-throwing getter being exposed
  934.     // in extension pages loaded into a non-extension process (only happens for remote client
  935.     // extensions)
  936.     var devtools_descriptor = Object.getOwnPropertyDescriptor(chrome, "devtools");
  937.     if (!devtools_descriptor || devtools_descriptor.get)
  938.         Object.defineProperty(chrome, "devtools", { value: {}, enumerable: true });
  939.     // Only expose tabId on chrome.devtools.inspectedWindow, not webInspector.inspectedWindow.
  940.     chrome.devtools.inspectedWindow = {};
  941.     chrome.devtools.inspectedWindow.__defineGetter__("tabId", getTabId);
  942.     chrome.devtools.inspectedWindow.__proto__ = coreAPI.inspectedWindow;
  943.     chrome.devtools.network = coreAPI.network;
  944.     chrome.devtools.panels = coreAPI.panels;
  945.  
  946.     // default to expose experimental APIs for now.
  947.     if (extensionInfo.exposeExperimentalAPIs !== false) {
  948.         chrome.experimental = chrome.experimental || {};
  949.         chrome.experimental.devtools = chrome.experimental.devtools || {};
  950.  
  951.         var properties = Object.getOwnPropertyNames(coreAPI);
  952.         for (var i = 0; i < properties.length; ++i) {
  953.             var descriptor = Object.getOwnPropertyDescriptor(coreAPI, properties[i]);
  954.             Object.defineProperty(chrome.experimental.devtools, properties[i], descriptor);
  955.         }
  956.         chrome.experimental.devtools.inspectedWindow = chrome.devtools.inspectedWindow;
  957.     }
  958.     if (extensionInfo.exposeWebInspectorNamespace)
  959.         window.webInspector = coreAPI;
  960. }
  961.  
  962.         var tabId;
  963.         var extensionInfo = {};
  964.         platformExtensionAPI(injectedExtensionAPI("remote-" + window.parent.frames.length));
  965.     })();